package cn.iocoder.yudao.module.crossborder.order.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.order.api.dto.OrderCreateReqDTO;
import cn.iocoder.yudao.module.crossborder.order.api.dto.OrderDTO;
import cn.iocoder.yudao.module.crossborder.order.service.OrderService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 订单管理 API 接口实现类
 *
 * @author LHL
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class OrderApiImpl implements OrderApi {

    @Resource
    private OrderService orderService;

    @Override
    public CommonResult<OrderDTO> getOrder(Long id) {
        OrderDTO order = orderService.getOrder(id);
        return success(order);
    }

    @Override
    public CommonResult<List<OrderDTO>> getOrderList(List<Long> ids) {
        List<OrderDTO> orders = orderService.getOrderList(ids);
        return success(orders);
    }

    @Override
    public CommonResult<Long> createOrder(OrderCreateReqDTO createReq) {
        Long id = orderService.createOrder(createReq);
        return success(id);
    }

    @Override
    public CommonResult<Boolean> cancelOrder(Long orderId, String reason) {
        Boolean result = orderService.cancelOrder(orderId, reason);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> confirmOrder(Long orderId) {
        Boolean result = orderService.confirmOrder(orderId);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> payOrder(Long orderId, Integer paymentMethod) {
        Boolean result = orderService.payOrder(orderId, paymentMethod);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> fulfillOrder(Long orderId) {
        Boolean result = orderService.fulfillOrder(orderId);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> completeOrder(Long orderId) {
        Boolean result = orderService.completeOrder(orderId);
        return success(result);
    }

}
